﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Data.SqlClient;
using QL_DTTN.DTO;
using QL_DTTN.DTO.DTO;
using QL_DTTN.KQT.BUS;

namespace QL_DTTN.KQT
{
    public partial class FrmXuatLichThi : DevExpress.XtraEditors.XtraForm
    {
        List<KyThi> _kyThi;
        public FrmXuatLichThi()
        {
            InitializeComponent();
            _kyThi = new List<KyThi>();
            

        }
        //private DataTable HienDS()
        //{
        //    String strConnect = "Data Source=tieuphung-pc;Initial Catalog=dbQLDTTN;Integrated Security=True";
        //    SqlConnection connect = new SqlConnection(strConnect);
        //    connect.Open();

        //    SqlCommand command = new SqlCommand("select ThiSinh.soBaoDanh, hoTen, tenKyThi, tenPhongThi, tenDiemThi, DiemThi.diaChi, tenMon from DiemThi, Mon, MonThi, PhongThi, LichThi, KyThi, ThiSinh where Mon.maMon = MonThi.maMon and MonThi.maMonThi = LichThi.maMonThi and PhongThi.maPhongThi = LichThi.maPhongThi and PhongThi.maDiemThi=DiemThi.maDiemThi and ThiSinh.soBaoDanh=LichThi.soBaoDanh and ThiSinh.maKyThi=KyThi.maKyThi and KyThi.maKyThi='" + cbxChonkyThi.SelectedValue + "'", connect);
        //    SqlDataAdapter adapter = new SqlDataAdapter(command);
        //    DataTable ds = new DataTable();
        //    adapter.Fill(ds);
        //    return ds;
        //}/// hàm này hok dc sai ơ dây,, qua dto xay dụng 1 hàm tra về 1 datatable rồi qua bus tạo 1 hàm sử dụng hàm đó.. rồi mới qua đây gọi lại

        private void FrmXuatLichThi_Load(object sender, EventArgs e)
        {
            //cbxChonkyThi_Load();
            
            cbxTinh_Load();
            cbxHeDaoTao_Load();
            cbxKyThi_Load();
            cbxTinh_SelectedIndexChanged(sender, e);
            cbxKyThi_SelectedIndexChanged(sender, e);

        }
        private void cbxTinh_Load()
        {
            DataTable dt = Tinh_Bus.dataTable();
            DataRow d = dt.NewRow();
            d["maTinh"] = 0;
            d["tenTinh"] = "Tất cả";
            dt.Rows.Add(d);
            cbxTinh.DataSource = dt;
            cbxTinh.DisplayMember = "tenTinh";
            cbxTinh.ValueMember = "maTinh";
            cbxTinh.SelectedIndex = cbxTinh.Items.Count - 1;
        }
        private void cbxTinh_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                if (cbxTinh.SelectedIndex != -1 && cbxTinh.SelectedValue.ToString() != "System.Data.DataRowView")
                {
                    DataTable dt = Truong_Bus.dataTable(Convert.ToInt32(cbxTinh.SelectedValue));
                    DataRow d = dt.NewRow();
                    d["maTruong"] = 0;
                    d["tenTruong"] = "Tất cả";
                    dt.Rows.Add(d);
                    cbxTruong.DataSource = dt;
                    cbxTruong.DisplayMember = "tenTruong";
                    cbxTruong.ValueMember = "maTruong";
                    cbxTruong.SelectedIndex = cbxTruong.Items.Count - 1;
                }
            }
            catch
            {

            }
        }

        private void cbxHeDaoTao_Load()
        {
            DataTable dt = HeDaoTao_Bus.dataTable();
            DataRow d = dt.NewRow();
            d["maHeDaoTao"] = 0;
            d["tenHeDaoTao"] = "Tất cả";
            dt.Rows.Add(d);
            cbxHeDaoTao.DataSource = dt;
            cbxHeDaoTao.DisplayMember = "tenHeDaoTao";
            cbxHeDaoTao.ValueMember = "maHeDaoTao";
            cbxHeDaoTao.SelectedIndex = cbxHeDaoTao.Items.Count - 1;
        }
        private void cbxKyThi_Load()
        {
            DataTable dt = KyThi_Bus.dataTable();
            cbxKyThi.DataSource = dt;
            cbxKyThi.ValueMember = "maKyThi";
            cbxKyThi.DisplayMember = "tenKyThi";
        }
                
        private void cbxKyThi_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                if (cbxKyThi.SelectedIndex != -1 && cbxKyThi.SelectedValue.ToString() != "System.Data.DataRowView")
                {
                    DataTable dt = MonThi_Bus.dataTable(Convert.ToInt32(cbxKyThi.SelectedValue));
                    cbxMonThi.DataSource = dt;
                    cbxMonThi.DisplayMember = "TenMon";
                    cbxMonThi.ValueMember = "MaMonThi";
                }
            }
            catch
            {

            }
        }

        //private void cbxChonkyThi_SelectedIndexChanged(object sender, EventArgs e)
        //{

        //}
        //private void cbxChonkyThi_Load()
        //{
        //    cbxChonkyThi.DataSource = KyThi_Bus.dataTable();
        //    cbxChonkyThi.ValueMember = "maKyThi";
        //    cbxChonkyThi.DisplayMember = "tenKyThi";

        //}

        //private void btnOK_Click(object sender, EventArgs e)
        //{
        //    rptLichThi rpt = new rptLichThi();
        //    rpt.DataSource = LichThi_Bus.getData(txtThongTin.Text.Trim().ToString(), Convert.ToInt16(cbxTinh.SelectedValue), cbxTruong.SelectedValue.ToString(), Convert.ToInt16(cbxHeDaoTao.SelectedValue), Convert.ToInt64(cbxKyThi.SelectedValue), Convert.ToInt64(cbxMonThi.SelectedValue));
        //    //rpt.DataSource = LichThi_Bus.dataTable(Convert.ToInt64(cbxChonkyThi.SelectedValue));
        //    rpt.BindData();

        //    printControl1.PrintingSystem = rpt.PrintingSystem;
        //    rpt.CreateDocument();

            
        //}

        private void btnTim_Click(object sender, EventArgs e)
        {
            rptLichThi rpt = new rptLichThi();
            rpt.DataSource = LichThi_Bus.getLichThi(txtThongTin.Text.Trim().ToString(), Convert.ToInt16(cbxTinh.SelectedValue), cbxTruong.SelectedValue.ToString(), Convert.ToInt16(cbxHeDaoTao.SelectedValue), Convert.ToInt64(cbxKyThi.SelectedValue), Convert.ToInt64(cbxMonThi.SelectedValue));
            //rpt.DataSource = LichThi_Bus.dataTable(Convert.ToInt64(cbxChonkyThi.SelectedValue));
            rpt.BindData();
            // có thiết kế chọn tiêu đề thì sài cái hàm đó nhe :D
           // rpt.SetTieuDe("Ky thi nè:");
            printControl1.PrintingSystem = rpt.PrintingSystem;
            rpt.CreateDocument();
        }


    }
}